package com.android.kmlmrg.dao;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.util.Log;

public class PhotoDao {


	/**LOG**/
	private static final  String LOG_TAG = PhotoDao.class.getName();


	public byte[] findPhotoById ( Context pContext, String idPhoto) {
		String[] projection ;		
		Log.i(LOG_TAG, "ID : " + idPhoto );
		byte[] photoBlob  = null;
		if (idPhoto != null) {
			String where = ContactsContract.Data.PHOTO_ID + " = " + idPhoto;
			projection = new String[] {
					Photo.PHOTO,	
			};
			Cursor dataCursor =
					pContext.getContentResolver().query(ContactsContract.Data.CONTENT_URI,
							projection, where, null, null);

			int photoIdx =
					dataCursor.getColumnIndexOrThrow(
							ContactsContract.Data.PHOTO_ID);
			while(dataCursor.moveToNext()) { 
				photoBlob = dataCursor.getBlob(photoIdx);			
				Log.i(LOG_TAG, "Photo : " + photoBlob );
			}

			dataCursor.close();
		}
		return photoBlob;
	}

}
